/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kindatamanip;

import java.util.ArrayList;

/**
 *
 * @author thbrandston
 */
public class Heuristics {

    public static ArrayList<ArrayList<DipOrg>> percentBased(int percent, DipOrg[] chil, int nChecks)
    {
        //grab the first child, add it to a new list, create an average genome? // alternatively:
        //loop next child                                                       // loop children
        //  loop each list                                                      //   loop lists
        //    if child > 80% similar to average genome for this list            //     if child more similar to this list than max similarity
        //      add child to list, avg genome                                   //       this similarity is new max
        //      break;                                                          //   if max > 80%
        //  if(!added to a list)                                                //     add to max list
        //    add it to a new list, create an average genome                    //   else
        //                                                                      //     create new list & average
        ////optionally:
        //loop each child in a random order
        //  loop each list
        //    if(similar to this list > similar to my list)
        //      remove child from my list
        //      add child to this list
        //      update averages

        //return the sibLists
        // we need to be able to compare the prediction made by this to the actual parents
        // so, we could return a ArrayList<ArrayList<DipOrg>> sibLists which can then be compared to actual siblists

        ArrayList<ArrayList<DipOrg>> sibLists = new ArrayList<ArrayList<DipOrg>>(0);
        ArrayList<AverageGenome> averages = new ArrayList<AverageGenome>(0);

        for(int i = 0; i < chil.length; i++)
        {
            float maxSimilarity = 0;
            int mostSimilar = -1;
            for(int j = 0; j < sibLists.size(); j++)
            {
                int similarity = Measurements.compareAlleles(chil[i], averages.get(j).getDO());
                if(similarity > maxSimilarity)
                {
                    maxSimilarity = similarity;
                    mostSimilar = j;
                }
            }
            System.out.println((maxSimilarity/chil[i].variation));
            if(maxSimilarity/chil[i].variation > percent/100.0)
            {
                sibLists.get(mostSimilar).add(chil[i]);
                averages.get(mostSimilar).addGenome(chil[i]);
            }
            else
            {
                sibLists.add(new ArrayList<DipOrg>(0));
                averages.add(new AverageGenome());
                sibLists.get(sibLists.size()-1).add(chil[i]);
                averages.get(averages.size()-1).addGenome(chil[i]);
                
            }
        }

        return sibLists;
    }

    
}
